<?php

class Field {

    private $StName;
    private $Value;
    private $ArRules;
    private $ArErrors;

    public function __construct($StName, $Value) {
        $this->StName = $StName;
        $this->Value = $Value;
        $this->ArRules = array();
    }

    public function addRule(Rule $Rule) {
        $this->ArRules[] = $Rule;
    }

    public function addRules(Array $Rules) {
        foreach($Rules as $Rule) {
            $this->addRule($Rule);
        }
    }

    public function isNotValid() {
        $BoNotValid = false;
        foreach ($this->ArRules as $Rule) {
            if (!$Rule->validate($this->Value)) {
                $BoNotValid = true;
                $this->ArErrors[] = $Rule->getMessage();
            }
        }
        return $BoNotValid;
    }

    public function getFieldErrors() {
        return $this->ArErrors;
    }

    public function getStName() {
        return $this->StName;
    }

}

?>
